package com.jaks.xpense.adapters;

import java.util.List;

import android.app.Activity;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.jaks.xpense.data.entities.Tile;

public class TileAdapter extends ArrayAdapter<Tile> {

	private final Activity context;
	private final List<Tile> list;
	private final int resource;
	private final int captionResourceId;
	private final int descriptionResourceId;

	public TileAdapter(Activity context, int resource, int captionResourceId,
	    int descriptionResourceId, List<Tile> list) {
		super(context, resource, captionResourceId, list);
		this.context = context;
		this.list = list;
		this.resource = resource;
		this.captionResourceId = captionResourceId;
		this.descriptionResourceId = descriptionResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = context.getLayoutInflater();
		View view = inflater.inflate(resource, null, true);

		view.setBackgroundColor(Color.parseColor(list.get(position).getColor()));

		TextView caption = (TextView) view.findViewById(captionResourceId);
		TextView description = (TextView) view.findViewById(descriptionResourceId);

		description.setText(list.get(position).getDescription());
		caption.setText(list.get(position).getCaption());

		return view;
	}
}
